#ifndef BULLETINTERFACE_H_
#define BULLETINTERFACE_H_

#include "Bullet/btBulletDynamicsCommon.h"
#include "Bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"

#include "irrlicht.h"

#include <vector>
#include <boost/shared_ptr.hpp>

namespace Facets {
	using namespace irr;
	class BulletInterface {
			std::vector<boost::shared_ptr<btCollisionObject> > m_Objects;
			std::vector<boost::shared_ptr<btCollisionShape> > m_CollisionShapes;
			int m_MaxProxies;
	        btVector3 m_AABBMin;
	        btVector3 m_AABBMax;
			btAxisSweep3* m_Broadphase;
			btDefaultCollisionConfiguration* m_CollisionConfig;
	        btCollisionDispatcher* m_Dispatcher;
	        btSequentialImpulseConstraintSolver* m_Solver;
	        btDiscreteDynamicsWorld* m_World;
	        
	        static BulletInterface* s_instance;
			

		public:
			BulletInterface();
			virtual ~BulletInterface();
		
			int addEntity(scene::IAnimatedMeshSceneNode* node);
			
			int addHeightmap();
			
			void addObject();
			
			void update(float dt) {
				m_World->stepSimulation(dt);
			}
			
			void setGravity(const core::vector3df& grav) {
				m_World->setGravity(btVector3(grav.X,grav.Y,grav.Z));
			}

			void drawDebug() {
				m_World->debugDrawWorld();
			}
			
			static void Initialize() {
				static bool instantiated = false;
				if(!instantiated) {
					s_instance = new BulletInterface();
					instantiated = true;
				}
			}
			static BulletInterface* Instance() {
				return s_instance;
			}			
	};

}

#endif /*BULLETINTERFACE_H_*/
